public class LineParticleEmitter extends ParticleEmitter {
  
  PImage images[];
  float angleInRadians;
  float radius;
  PVector locations[];
  PVector velocity[];
  float durationInMillis;
  int numberOfParticlesToUpdate = 0;
  float updateTime = 0;
  float startTime = 0;
  boolean continuous;
  float timeBetweenEmission;
  float xOrigin, yOrigin;
  
  public LineParticleEmitter(PImage images[], PVector location, float radius, float angleInRadians, PVector velocityMin, PVector velocityMax, float durationInMillis, boolean continuous, float timeBetweenEmission) {
    super(null, null, null, 0,0,0, null, null);
    this.images = images;
    this.radius = radius;
    this.angleInRadians = angleInRadians;
    this.locations = new PVector[images.length];
    for(int i = 0; i < images.length; i++){
     locations[i] = new PVector(0,0); 
    }
    
    this.startTime = millis();
    this.velocity = new PVector[images.length];
    for(int i = 0; i < images.length; i++){
      this.velocity[i] = new PVector(0,0);
      this.velocity[i].x = random(velocityMin.x, velocityMax.x);
      this.velocity[i].y = random(velocityMin.y, velocityMax.y);
//     this.velocity[i].x = this.velocity[i].x*cos(angleInRadians);
//     this.velocity[i].y = -1*this.velocity[i].y*sin(angleInRadians); 
      if((angleInRadians >= PI/2) && (angleInRadians < PI)) {
        this.velocity[i].x = -1*velocity[i].x;
        this.velocity[i].y = -1*velocity[i].y;
      } else if((angleInRadians >= PI) && (angleInRadians < (3*PI/2))) {
        this.velocity[i].x = -1*velocity[i].x;
        this.velocity[i].y = velocity[i].y;
      } else if((angleInRadians >= (3*PI/2)) && (angleInRadians < (2*PI))) {
        this.velocity[i].x = velocity[i].x;
        this.velocity[i].y = velocity[i].y;
      } else {
        this.velocity[i].x = velocity[i].x;
        this.velocity[i].y = -1*velocity[i].y;
      } 
    }
    this.continuous = continuous;
    this.durationInMillis = durationInMillis;
    this.timeBetweenEmission = timeBetweenEmission;
    this.xOrigin = location.x;
    this.yOrigin = location.y;
  }
  
  void updateLocation(float xLocation, float yLocation){
    xOrigin = xLocation;
    yOrigin = yLocation;
  }
  
  
  void updateParticles(){
    float currentTime = millis();
    if(continuous == true){
     startTime = currentTime; 
    }
    if(currentTime - startTime <= durationInMillis){
    float distance;
    if(currentTime - updateTime > timeBetweenEmission){
      updateTime = currentTime;
      if(numberOfParticlesToUpdate != (images.length -1)){
        numberOfParticlesToUpdate++;
      }
    }
    for(int i = 0; i < numberOfParticlesToUpdate; i++){
        locations[i].add(velocity[i]);
        distance = sqrt(sq(locations[i].x) + sq(locations[i].y));
        if(distance > radius){
          locations[i].set(0.0,0.0, 0.0);
        }      
        image(images[i], (xOrigin + locations[i].x), (yOrigin + locations[i].y));
      }
    
    }
  }
}
